package com.cl.short_video_java.web.log;

import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.annotation.Log;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.mapper.SysMailLogMapper;
import com.cl.short_video_java.menum.BusinessType;
import com.cl.short_video_java.pojo.SysMailLog;
import com.cl.short_video_java.service.SysMailLogService;
import com.cl.short_video_java.vo.sys.MailLogExceSearch;
import com.github.pagehelper.PageInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/maillog")
public class SysMailLogController {
    @Resource
    private SysMailLogService sysMailLogService;

    /**
     * 导出数据
     * @param mailLogExceSearch
     * @return
     * @throws IOException
     */
    @PostMapping("/exce")
    @Login(issuer = Const.GRADE_ADMIN)
    @IsRole(menuId = 12)
    public ResponseEntity<byte[]> getExce(@RequestBody MailLogExceSearch mailLogExceSearch) throws IOException {
        return sysMailLogService.getExceService(mailLogExceSearch);
    }

    /**
     * 清空数据
     * @return
     */
    @PostMapping("/clear")
    @Log(title = "系统日志清空",businessType = BusinessType.OTHER)
    @Login(issuer = Const.GRADE_ADMIN)
    @IsRole(menuId = 12)
    public Result Clear(){
        return Result.success(sysMailLogService.clearService());
    }

    /**
     * 删除
     * @param idlist 参数：1，2，3
     * @return
     */
    @PostMapping("/del")
    @Log(title = "系统日志",businessType = BusinessType.DELETE)
    @Login(issuer = Const.GRADE_ADMIN)
    @IsRole(menuId = 12)
    public Result Delete(@RequestParam("idlist") String idlist){
        return Result.success(sysMailLogService.DeleteService(idlist));
    }

    @PostMapping("/page")
    @Login(issuer = Const.GRADE_ADMIN)
    @IsRole(menuId = 12)
    public Result getPageMailLog(@RequestBody MailLogExceSearch mailLogExceSearch){
        return Result.success(sysMailLogService.getPageMailLogService(mailLogExceSearch));
    }
}
